<?php

namespace App\Kuafu\Dashboard\Controller\Internal;

use App\Kuafu\Base\Controller\BaseController;
use App\Kuafu\Common\Enum\CodeEnum;
use App\Kuafu\Dashboard\Service\DashboardService;
use App\Kuafu\Shop\Enum\CodeEnum as ShopEnum;
use App\Kuafu\Shop\Service\ShopService;
use App\Kuafu\User\Enum\RoleCodeEnum;
use App\Kuafu\User\Model\UserRoleMapping;
use Illuminate\Http\Request;

class DashboardController extends BaseController
{
    public function shops(Request $request)
    {
        $userId = (int)$request->get('userId', 0);
        $list   = ShopService::getShopListByUserAndPlatform($userId, CodeEnum::PLATFORM_BUSINESS,
            ['status' => [ShopEnum::SHOP_STATUS_NORMAL, ShopEnum::SHOP_STATUS_PREPARE]]);
        return $this->success(compact('list'));
    }

    public function permissions(Request $request)
    {
        $userId = (int)$request->get('userId', 0);
        $brandId = (int)$request->get('brandId', 0);
        $shopId = (int)$request->get('shopId', 0);
        $role   = (int)$request->get('role', RoleCodeEnum::ROLE_BUSINESS_TYPE);
        $platform = (int)$request->get('platform', CodeEnum::PLATFORM_BUSINESS);

        // 获取当前用户的角色 ID
        $roleList = UserRoleMapping::getUserRoleList($userId, $brandId, $shopId, $role);
        $menusList = DashboardService::getMenusV2($roleList->pluck('roleId')->toArray(), $platform);
        return $this->success($menusList);
    }
}
